home *** CD-ROM | disk | FTP | other *** search
/ Desktop Publisher's Dream 1994 / Desktop Publisher's Dream 1994.iso / prog_c / grafxlib.arc / GRAFSEC2.TEX < prev    next >
Text File  |  1987-09-01  |  15KB  |  526 lines

  1. \manpage intro(2)
  2.  
  3. \manname
  4.     intro --- introduction to halo emulation library
  5. \mandscr
  6.     The halo emulation library is a collection of routines that
  7.     emulate some of the most frequently used routines of the
  8.     popular HALO graphics library. It was written to assist in
  9.     converting HALO programs to the Grafix library.
  10.  
  11.     To use the halo functions, you should include the
  12.     file \bfwd halo.h at the start of your program and
  13.     link with the graphics library as usual.
  14.  
  15.     Most of these functions are fairly straightforward; however,
  16.     there are a few things you should be aware of. First of
  17.     all, and probably most important, all the parameters to all
  18.     the halo routines must be passed by reference, i.e., you must pass
  19.     pointers to the desired arguments to the graphics routines, not
  20.     the arguments themselves. Second, the halo routines
  21.     remember one point, called the graphics cursor, and
  22.     a color, called the current drawing color. The halo
  23.     drawing routines use these values instead of explicitly
  24.     passed parameters in many instances. They may be set with
  25.     the \itnc movabs , \itnc movrel , and \itwd setcolor functions.
  26.     And third, the halo drawing routines always take
  27.     world coordinates, never device coordinates (as is
  28.     possible in the original HALO library).
  29. \manex
  30. \vinput grafex2.c
  31. \manpend
  32.  
  33. \manpage box(2)
  34.  
  35. \manname
  36.     box --- draw a rectangular box
  37. \mansyn
  38.     void box(x1, y1, x2, y2)
  39.  
  40.     float *x1, *y1, *x2, *y2;
  41. \mandscr
  42.     The \itwd box function draws the rectangular box defined by the points
  43.     \itpnt (*x1, *y1) and \itpnt (*x2, *y2) (in world coordinates)
  44.     in the current drawing buffer with the current drawing color.
  45.     If xor mode is on, the rectangle is logically xor'ed with the
  46.     existing data in the buffer.
  47. \mansee
  48.     g_box(1).
  49. \manpend
  50.  
  51. \manpage cir(2)
  52.  
  53. \manname
  54.     cir --- draw a circle
  55. \mansyn
  56.     void cir(r)
  57.  
  58.     float *r;
  59. \mandscr
  60.     The \itwd g_cir function draws a circle centered on the current
  61.     graphics cursor with radius~\itwd r (in world coordinates).
  62.     The circle is drawn in the current drawing buffer with the current
  63.     drawing color. If xor mode is
  64.     on, the circle is logically xor'ed with the existing data in the
  65.     buffer. The radius is taken to be half of the horizontal diameter
  66.     of the circle, in world coordinates.
  67. \mansee
  68.     g_circle(1).
  69. \manpend
  70.  
  71. \manpage coordinates(2)
  72.  
  73. \manname
  74.     coordinates --- coordinate systems used
  75. \mandscr
  76.     The halo routines utilize three different coordinate
  77.     systems: device, normalized device, and world. The following
  78.     sections explain these coordinate systems and their
  79.     interrelationships.
  80.  
  81. \manhead Device coordinates\par
  82.  
  83.     The first and simplest coordinate system is device coordinates.
  84.     In device coordinates, the origin is at the upper left
  85.     corner of the screen and the axes are scaled in pixels.
  86.     Thus in the four-color mode of the CGA, for example,
  87.     device coordinates range from (0, 0) to (319, 199).
  88.     All the graphics routines listed in section 1 of this manual
  89.     use device coordinates.
  90.     Device coordinates are always expressed as integers.
  91.  
  92. \vskip\baselineskip
  93. \centerline{\vbox{%
  94.   \hbox to 4in{(0, 0)\hfill (319, 0)}%
  95.   \smallskip
  96.   \hrule width4in
  97.   \hbox to 4in{\vrule height3in
  98.                \hfill
  99.                \vbox to 3in{\vfill\hbox{Device coordinates}\vfill}%
  100.                \hfill
  101.                \vrule height3in}%
  102.   \hrule width4in
  103.   \smallskip
  104.   \hbox to 4in{(0, 199)\hfill (319, 199)}%
  105. }}
  106. \bigskip
  107.  
  108. \manhead Normalized device coordinates\par
  109.  
  110.     In normalized device coordinates, the origin is still the
  111.     upper left corner of the screen, but the point (1.0, 1.0)
  112.     is fixed at the lower right corner. This allows one to specify
  113.     coordinates without knowing the physical size of the screen.
  114.     Normalized device coordinates are always expressed as floats.
  115.  
  116. \vskip\baselineskip
  117. \centerline{\vbox{%
  118.   \hbox to 4in{(0.0, 0.0)\hfill (1.0, 0.0)}%
  119.   \smallskip
  120.   \hrule width4in
  121.   \hbox to 4in{\vrule height3in
  122.                \hfill
  123.                \vbox to 3in{\vfill\hbox{Normalized device coordinates}\vfill}%
  124.                \hfill
  125.                \vrule height3in}%
  126.   \hrule width4in
  127.   \smallskip
  128.   \hbox to 4in{(0.0, 1.0)\hfill (1.0, 1.0)}%
  129. }}
  130. \bigskip
  131.  
  132. \manhead World coordinates\par
  133.  
  134.     In world coordinates you can set up a coordinate system
  135.     with an arbitrary offset and scale. For example, if you
  136.     want to have the x coordinates range from $-100$ to $+100$
  137.     and the y coordinates range from $-50$ to $+50$, you would
  138.     call the \itwd setworld function as follows:
  139. \mancodebeg
  140.       x1 = -100.0;        /* lower left corner */
  141.       y1 = -50.0;
  142.       x2 = 100.0;        /* upper right corner */
  143.       y2 = 50.0;
  144.       setworld(&x1, &y1, &x2, &y2);
  145. \mancodeend
  146.     This sequence results in the following situation:
  147.  
  148. \vskip\baselineskip
  149. \centerline{\vbox{%
  150.   \hbox to 4in{($-$100.0, 50.0)\hfill (100.0, 50.0)}%
  151.   \smallskip
  152.   \hrule width4in
  153.   \hbox to 4in{\vrule height3in
  154.                \hfill
  155.                \vbox to 3in{\vfill\hbox{World coordinates}\vfill}%
  156.                \hfill
  157.                \vrule height3in}%
  158.   \hrule width4in
  159.   \smallskip
  160.   \hbox to 4in{($-$100.0, $-$50.0)\hfill (100.0, $-$50.0)}%
  161. }}
  162. \bigskip
  163.  
  164. \manhead Coordinate transformations\par
  165.  
  166.     The following routines are available for converting points
  167.     from one coordinate system to another:
  168. {\obeylines
  169.       mapdton --- convert device to normalized device coordinates
  170.       mapdtow --- convert device to world coordinates
  171.       mapntod --- convert normalized device to device coordinates
  172.       mapntow --- convert normalized device to world coordinates
  173.       mapwtod --- convert world to device coordinates
  174.       mapwton --- convert world to normalized device coordinates
  175. }
  176.  
  177. \manhead Viewports\par
  178.  
  179.     Viewports allow one to draw only on a portion of the screen.
  180.     For example, if we wanted the same coordinate system as
  181.     we had in the last example but we wanted to use only the
  182.     upper left corner of the screen, we could use:
  183. \mancodebeg
  184.       x1 = 0.0;   /* upper left corner of viewport in NDC */
  185.       y1 = 0.0;
  186.       x2 = 0.5;   /* lower right corner of viewport in NDC */
  187.       y2 = 0.5;
  188.       c = -1;     /* no border or clearing */
  189.       setviewport(&x1, &y1, &x2, &y2, &c, &c);
  190.  
  191.       x1 = -100.0;  /* lower left corner */
  192.       y1 = -50.0;
  193.       x2 = 100.0;   /* upper right corner */
  194.       y2 = 50.0;
  195.       setworld(&x1, &y1, &x2, &y2);
  196. \mancodeend
  197.     This results in the following:
  198.  
  199. \vskip\baselineskip
  200. \centerline{\vbox{%
  201.   \hbox to 4in{($-$100.0, 50.0)\hfill \hbox to 2in{(100.0, 50.0)\hfill}}%
  202.   \smallskip
  203.   \hrule width 4in
  204.   \hbox to 4in{%
  205.     \vrule height 3in
  206.     \vbox to 3in{%
  207.       \hbox to 2in{%
  208.         \hfill
  209.         \vbox to 1.5in{%
  210.           \vfill
  211.           \hbox{\hfill Viewport\hfill}%
  212.           \vfill
  213.         }%
  214.         \hfill
  215.         \vrule height 1.5in
  216.       }%
  217.       \hrule width 2in
  218.       \smallskip
  219.       \hbox to 2in{($-$100.0, $-$50.0)\hfill}%
  220.       \vfill
  221.     }%
  222.     \vbox to 3in{%
  223.       \vskip 1.5in
  224.       \smallskip
  225.       \hbox{(100.0, $-$50.0)\hfill}%
  226.       \vfill
  227.     }%
  228.     \hfill
  229.     \vrule height 3in
  230.   }%
  231.   \hrule width 4in
  232. }}
  233. \bigskip
  234.  
  235.     Note that the viewport corners are specified using normalized
  236.     device coordinates.
  237. \mansee
  238.     mapdton(2),
  239.     mapdtow(2), mapntod(2), mapntow(2), mapwtod(2),
  240.     mapwton(2), \hint setworld(2), setviewport(2).
  241. \manpend
  242.  
  243. \manpage halo_init(2)
  244.  
  245. \manname
  246.     halo_init --- initialize the halo routines
  247. \mansyn
  248.     void halo_init()
  249. \mandscr
  250.     The \itwd halo_init function initializes the halo routines,
  251.     resets the viewport to the entire screen, and resets world
  252.     coordinates to device coordinates (i.e., x coordinates
  253.     range from 0 to the x size of the device, similarly for
  254.     y coordinates). It also moves the graphics cursor
  255.     to~(0, 0) and sets the current drawing color to~0.
  256.     This function must be called \itwd after
  257.     every call to \itwd g_open and \itwd before any
  258.     other halo routines are used.
  259. \mansee
  260.     g_open(1).
  261. \manpend
  262.  
  263. \manpage lnabs(2)
  264.  
  265. \manname
  266.     lnabs ---  draw a line to a specified point
  267. \mansyn
  268.     void lnabs(x, y)
  269.  
  270.     float *x, *y;
  271. \mandscr
  272.     The \itwd lnabs function draws a line from the current graphics
  273.     cursor position to the point~\itpnt (*x, *y) in world coordinates and
  274.     the graphics cursor is set to~\itpnt (*x, *y). The line is
  275.     drawn in the current drawing buffer with the current drawing
  276.     color. If xor mode is on the line is logically xor'ed with
  277.     the existing data in the buffer.
  278. \mansee
  279.     g_line(1), lnrel(2).
  280. \manpend
  281.  
  282. \manpage lnrel(2)
  283.  
  284. \manname
  285.     lnrel --- draw a line relative to the current graphics cursor position
  286. \mansyn
  287.     void lnrel(dx, dy)
  288.  
  289.     float *dx, *dy;
  290. \mandscr
  291.     The \itwd lnrel function draws a line from the current graphics
  292.     cursor to the point \break \itpnt ({cur_x + *dx}, {cur_y + *dy}) in
  293.     world coordinates, where \itpnt (cur_x, cur_y) is the current
  294.     position of the graphic cursor. After the line is drawn,
  295.     the graphics cursor is moved to \itpnt ({cur_x + *dx},
  296.     {cur_y + *dy}). The line is
  297.     drawn in the current drawing buffer with the current drawing
  298.     color. If xor mode is on the line is logically xor'ed with
  299.     the existing data in the buffer.
  300. \mansee
  301.     g_line(1), lnabs(2).
  302. \manpend
  303.  
  304. \manpage mapdton(2)
  305.  
  306. \manname
  307.     mapdton --- map device to normalized device coordinates
  308. \mansyn
  309.     void mapdton(dx, dy, nx, ny)
  310.  
  311.     int *dx, *dy;
  312.     float *nx, *ny;
  313. \mandscr
  314.     The \itwd mapdton function converts the device coordinates
  315.     \itpnt (*dx, *dy) to the corresponding normalized device
  316.     coordinates \itpnt (*nx, *ny).
  317. \mansee
  318.     coordinates(2),
  319.     mapdtow(2), mapntod(2), mapntow(2), mapwtod(2),
  320.     mapwton(2), setworld(2), setviewport(2).
  321. \manpend
  322.  
  323. \manpage mapdtow(2)
  324.  
  325. \manname
  326.     mapdtow --- map device to world coordinates
  327. \mansyn
  328.     void mapdtow(dx, dy, wx, wy)
  329.  
  330.     int *dx, *dy;
  331.     float *wx, *wy;
  332. \mandscr
  333.     The \itwd mapdtow function converts the device coordinates
  334.     \itpnt (*dx, *dy) to the corresponding world
  335.     coordinates \itpnt (*wx, *wy).
  336. \mansee
  337.     coordinates(2),
  338.     mapdton(2), mapntod(2), mapntow(2), mapwtod(2),
  339.     mapwton(2), setworld(2), setviewport(2).
  340. \manpend
  341.  
  342. \manpage mapntod(2)
  343.  
  344. \manname
  345.     mapntod --- map normalized device to device coordinates
  346. \mansyn
  347.     void mapntod(nx, ny, dx, dy)
  348.  
  349.     float *nx, *ny;
  350.     int *dx, *dy;
  351. \mandscr
  352.     The \itwd mapntod function converts the normalized device coordinates
  353.     \itpnt (*nx, *ny) to the corresponding device
  354.     coordinates \itpnt (*dx, *dy).
  355. \mansee
  356.     coordinates(2),
  357.     mapdton(2), mapdtow(2),  mapntow(2), mapwtod(2),
  358.     mapwton(2), setworld(2), setviewport(2).
  359. \manpend
  360.  
  361. \manpage mapntow(2)
  362.  
  363. \manname
  364.     mapntow --- map normalized device to world coordinates
  365. \mansyn
  366.     void mapntow(nx, ny, wx, wy)
  367.  
  368.     float *nx, *ny;
  369.     float *wx, *wy;
  370. \mandscr
  371.     The \itwd mapntow function converts the normalized device coordinates
  372.     \itpnt (*nx, *ny) to the corresponding world
  373.     coordinates \itpnt (*wx, *wy).
  374. \mansee
  375.     coordinates(2),
  376.     mapdton(2), mapdtow(2), mapntod(2), mapwtod(2),
  377.     mapwton(2), setworld(2), setviewport(2).
  378. \manpend
  379.  
  380. \manpage mapwtod(2)
  381.  
  382. \manname
  383.     mapwtod --- map world to device coordinates
  384. \mansyn
  385.     void mapwtod(wx, wy, dx, dy)
  386.  
  387.     float *wx, *wy;
  388.     int *dx, *dy;
  389. \mandscr
  390.     The \itwd mapwtod function converts the world coordinates
  391.     \itpnt (*wx, *wy) to the corresponding device
  392.     coordinates \itpnt (*dx, *dy).
  393. \mansee
  394.     coordinates(2),
  395.     mapdton(2), mapdtow(2), mapntod(2), mapntow(2),
  396.     mapwton(2), setworld(2), setviewport(2).
  397. \manpend
  398.  
  399. \manpage mapwton(2)
  400.  
  401. \manname
  402.     mapwton --- map world to normalized device coordinates
  403. \mansyn
  404.     void mapwton(wx, wy, nx, ny)
  405.  
  406.     float *wx, *wy;
  407.     float *nx, *ny;
  408. \mandscr
  409.     The \itwd mapwton function converts the world coordinates
  410.     \itpnt (*wx, *wy) to the corresponding normalized device
  411.     coordinates \itpnt (*nx, *ny).
  412. \mansee
  413.     coordinates(2),
  414.     mapdton(2), mapdtow(2), mapntod(2), mapntow(2), mapwtod(2),
  415.     setworld(2), setviewport(2).
  416. \manpend
  417.  
  418. \manpage movabs(2)
  419.  
  420. \manname
  421.     movabs --- move the graphics cursor to a specified point
  422. \mansyn
  423.     void movabs(x, y)
  424.  
  425.     float *x, *y;
  426. \mandscr
  427.     The \itwd movabs function moves the graphics cursor to the
  428.     position \itpnt (*x, *y) in world coordinates.
  429. \mansee
  430.     movrel(2).
  431. \manpend
  432.  
  433. \manpage movrel(2)
  434.  
  435. \manname
  436.     movrel --- move the graphics cursor relatively
  437. \mansyn
  438.     void movrel(dx, dy)
  439.  
  440.     float *dx, *dy;
  441. \mandscr
  442.     The \itwd movrel function moves the graphics cursor to the
  443.     position \itpntb ({cur_x + *dx}, {cur_y + *dy}) in world
  444.     coordinates where \itpnt (cur_x, cur_y) is the current position
  445.     of the graphics cursor.
  446. \mansee
  447.     movabs(2).
  448. \manpend
  449.  
  450. \manpage setcolor(2)
  451.  
  452. \manname
  453.     setcolor --- set the current drawing color
  454. \mansyn
  455.     void setcolor(c)
  456.  
  457.     int *c;
  458. \mandscr
  459.     The \itwd setcolor function sets the current drawing color
  460.     to~\itnc c . If~\itwd c is greater than the maximum color
  461.     value available on the graphics device in use, the
  462.     maximum value is used instead.
  463. \manpend
  464.  
  465. \manpage setviewport(2)
  466.  
  467. \manname
  468.     setviewport --- set the active viewport
  469. \mansyn
  470.     void setviewport(x1, y1, x2, y2, border, backgnd)
  471.  
  472.     float *x1, *y1, *x2, *y2;
  473.     int *border, *backgnd;
  474. \mandscr
  475.     The \itwd setviewport function sets the viewport and the
  476.     clipping boundaries to the rectangular area defined by the
  477.     points \itpnt (x1, y1) and \itpnt (x2, y2) in normalized device
  478.     coordinates. If \itwd border is not $-$1, a border of
  479.     color~\itwd border will be drawn around the viewport (if there is
  480.     room for it), and if~\itwd backgnd is not $-$1, the interior
  481.     of the viewport will be cleared to color~\itnc backgnd .
  482. \mansee
  483.     g_setclip(1), coordinates(2), setworld(2).
  484. \manpend
  485.  
  486. \manpage setworld(2)
  487.  
  488. \manname
  489.     setworld --- set world coordinates
  490. \mansyn
  491.     void setworld(x1, y1, x2, y2)
  492.  
  493.     float *x1, *y1, *x2, *y2;
  494. \mandscr
  495.     The \itwd setworld function changes the current world coordinate
  496.     system. The world coordinates of the lower left corner of
  497.     the viewport become \itpnt (x1, y1), and the world
  498.     coordinates of the upper right corner of the viewport
  499.     become \itpnt (x2, y2).
  500. \mansee
  501.     coordinates(2), setviewport(2).
  502. \manpend
  503.  
  504. \manpage setxor(2)
  505.  
  506. \manname
  507.     setxor --- turn xor mode on or off
  508. \mansyn
  509.     void setxor(flag)
  510.  
  511.     int *flag;
  512. \mandscr
  513.     The \itwd setxor function turns xor mode on if \itwd~*flag
  514.     is nonzero, or off if \itwd~*flag is zero. When xor mode is
  515.     off, drawn objects are simply written over existing data in
  516.     the drawing buffer. But if xor mode is on, drawn objects
  517.     are logically xor'ed with the existing data. Thus if an object
  518.     is drawn twice in a row in exactly the same position with xor
  519.     mode on, it will be completely erased after the second drawing
  520.     and the image on the
  521.     screen restored to its state previous to the first drawing.
  522.     This makes xor mode useful for animation and other effects.
  523.     Functions which support xor mode are {\it g_box, g_circle,
  524.     g_ellipse, g_line, g_point, box, cir, lnabs,} and \itnc lnrel .
  525. \manpend
  526.